from sqlalchemy import (
    MetaData,
    Table,
    Column,
    Integer,
    String,
    ForeignKey,
)
from en_url import engine

try:
    connection = engine.connect()
    print("连接MYSQL成功")
    connection.close()
except Exception as e:
    print(f"数据库连接失败:{e}")
# 创建元数据对象，保存表结构
metadata = MetaData()
# 定义users表
users = Table(
    "users",
    metadata,
    Column("id", Integer, primary_key=True),
    Column(
        "name",
        String(50),
    ),
    Column("fullname", String(100)),
)
# 用户的收货地址表
addresses = Table(
    "addresses",
    metadata,
    Column("id", Integer, primary_key=True),
    Column("user_id", None, ForeignKey("users.id")),
    Column("email_address", String(100), nullable=False),
)
# 在数据库中创建所有的定义的
metadata.create_all(engine)
print("创建表成功")
